package com.sf.sgs.sessionevaluate.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Component;

import com.sf.sgs.sessionevaluate.dao.IQuestionDao;
import com.sf.sgs.sessionevaluate.domain.Question;
import com.sf.sgs.sessionevaluate.domain.Questionnaire;
import com.sf.sgs.sessionevaluate.service.IQuestionService;

@Component
public class QuestionServiceImpl extends TransactionalService implements IQuestionService {

	@Autowired
	private IQuestionDao questionDao;

	@Override
	public List<Question> getByQuestionnaireId(Long questionnaireId) {
		Question question = new Question();
		Questionnaire questionnaire = new Questionnaire();
		questionnaire.setId(questionnaireId);
		question.setQuestionnaire(questionnaire);

		Example<Question> example = Example.of(question);
		Sort sort = new Sort(Direction.ASC, "orderIndex");
		return questionDao.findAll(example, sort);
	}

}
